<template>
    公告标题:
    <input type="text" v-model="title">
    公告类型:
    <select v-model="tid">
        <option :value="-1">--请选择--</option>
        <option v-for="item in bindt" :value="item.ntid">{{item.ntname}}</option>
    </select>
    <input type="button" value="查询" class="btn btn-info" @click="show">
    <input type="button" value="导出" class="btn btn-success" @click="exp">
    <table border="1" class="table table-bordered">
        <thead>
            <tr>
                <td>公告标题</td>
                <td>公告内容</td>
                <td>公告状态</td>
                <td>发布人</td>
                <td>发起时间</td>
                <td>公告类型</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="item in info"> 
                <td>{{item.ntitle}}</td>
                <td>{{item.ncontent}}</td>
                <td>{{item.nstate?"显示":"隐藏"}}</td>
                <td>{{item.sendpeo}}</td>
                <td>{{moment(item.createtime).format("YYYY-MM-DD HH:mm:ss")}}</td>
                <td>{{item.ntname}}</td>
                <td>操作</td>
            </tr>
        </tbody>
    </table>
</template>
<script setup lang="ts">
import { onMounted } from 'vue';
import axios from 'axios';
import {ref} from 'vue'
import moment from 'moment';
onMounted(()=>{
    bind();
    show();
})
const exp=()=>{
    const path="D:/专高二作业考试代码/日考/刘百世1.6月考/Notice.xlsx";
    axios.post('http://localhost:63668/api/Notice/ExportNotice?path='+path)
    .then(res=>{
        if(res.data>0){
            alert('导出成功');
        }
        else{
            alert('导出失败');
        }
    })
    .catch(error=>{
        console.log(error);
    })
}
const info=ref([{
    "nid": 0,
    "ntitle": "",
    "ncontent": "",
    "nstate": true,
    "sendpeo": "",
    "createtime": "",
    "ntid": "",
    "ntname": ""
}])
const bindt=ref([{
    "ntid": 0,
    "ntname": ""
}])
const bind=()=>{
    axios.get('http://localhost:63668/api/Notice/Bind_t')
    .then(res=>{
        bindt.value=res.data
    })
    .catch(error=>{
        console.log(error);
    })
}
const tid=ref(-1);
const title=ref('');
const show=()=>{
    axios.get('http://localhost:63668/api/Notice/ShowNotice',{
        params:{
            name:title.value,
            tid:tid.value
        }
    })
    .then(res=>{
        info.value=res.data
    })
    .catch(error=>{
        console.log(error);
    })
}
</script>